﻿using System;
using System.Web.Mvc;

namespace DataApi.Controllers
{
    public class DataController : Controller
    {
        // GET: /Data/
        public ActionResult Index()
        {
            return View();
        }

        /// <summary>
        /// Get: /m/ Runs a method by name
        /// </summary>
        /// <param name="method">The name of the method to run</param>
        /// <returns>json data string by default</returns>
        public ActionResult RunMethod(String method)
        {
            return new EpicCmsResult { Param1 = method, Param2 = Request.QueryString, ExecuteWithTwoParam = EpicDataHelper.ExecuteStoredProcedureAnon };            
        }

        /// <summary>
        /// Get: /h/
        /// </summary>
        /// <param name="dataname">The name of the data to get the header information for</param>
        /// <returns>json data string by default</returns>
        public ActionResult GetDataHeader(String dataname)
        {
            return new EpicCmsResult { Param1 = dataname, ExecuteWithOneParam = EpicDataHelper.GetDataHeaderAnon };
        }

        //[RequireHttps]
        /// <summary>
        /// Get: /d/ returns data in the format requested by name and id
        /// </summary>
        /// <param name="dataname">The name of the data to get</param>
        /// <param name="id">Optional: the id of the data</param>
        /// <returns>json data string by default</returns>
        public ActionResult GetData(String dataname, String id)
        {
            return new EpicCmsResult { Param1 = dataname, Param2 = id, ExecuteWithTwoParam = EpicDataHelper.GetDataFromTableAnon };            
        }

        //[RequireHttps]
        /// <summary>
        /// Get: /id/ returns data in the format requested by the id
        /// </summary>
        /// <param name="id">The id of the data</param>
        /// <returns>json data string by default</returns>
        public ActionResult GetDataById(String id)
        {
            return new EpicCmsResult { Param1 = id, ExecuteWithOneParam = EpicDataHelper.GetDataByIdAnon };
        }

        public ActionResult SetupDatabase()
        {
            return new EpicCmsResult { ExecuteWithNoParam = EpicDataHelper.RunDatabaseSetupProcedures };            
        }
    }
}